<template >
  <div  v-loading="true" style="height:100%;width: 100%;">
    <h1>loading...</h1>

  </div>
</template>

<script>
import Home from '../../views/Home.vue'
import { query } from "../../api/api";
export default {
  mounted() {
    let key = JSON.parse(sessionStorage.getItem("key"));
    let params = { token: key };
    query(params).then(r => {
      if (r.code !== 0) {
        this.$message({
          message: r.message,
          type: "error"
        });
      } else {
        // sessionStorage.setItem("menu", JSON.stringify(r.data.list));
        
        this.$router.push({ path: "/home_page" });
      }
    });
  }
};
function routerGo(to, next) {
 
  getRouter = filterAsyncRouter(getRouter); //过滤路由
   console.log(getRouter)
  router.addRoutes(getRouter); //动态添加路由
  global.antRouter = getRouter; //将路由数据传递给全局变量，做侧边栏菜单渲染工作
  next({ ...to, replace: true });
}

function saveObjArr(name, data) {
  //localStorage 存储数组对象的方法
  localStorage.setItem(name, JSON.stringify(data));
}

function getObjArr(name) {
  //localStorage 获取数组对象的方法
  return JSON.parse(window.localStorage.getItem(name));
}
function _import(s){

}
function filterAsyncRouter(asyncRouterMap) { //遍历后台传来的路由字符串，转换为组件对象
  const accessedRouters = asyncRouterMap.filter(route => {
    if (route.path) {
      // if (route.component === 'Layout') { //Layout组件特殊处理
      //   route.component = Layout
      // } else {
      route.component = Home
      // }
    }
    if (route.children && route.children.length) {
      route.children = filterAsyncRouter(route.children)
    }
    return true
  })

  return accessedRouters
}
</script>